package com.huanzhidadi.jsoup;

import lombok.extern.slf4j.Slf4j;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.net.URL;

@Slf4j
public class JsoupDemo {
    public static void main(String[] args) throws IOException {
        // 解析url地址,后面的1000ms指解析时间
        Document document = Jsoup.parse(new URL("http://blog.huanzhidadi.com/"), 1000);

        Elements elementsByClass = document.getElementsByClass("article-box-content");
        // Elements elements = document.select(".article-title > a");
        for (Element element : elementsByClass) {
            Element title = element.selectFirst(".article-title > a");
            Element content = element.selectFirst(".article-content");
            log.info("title: {}, url: http://blog.huanzhidadi.com{}, 正文: {}",
                    title.text(), title.attr("href"), content.text());
        }

    }
}
